package com.lgc.leetcode.easy.reverseInt;

public class Program {
    public static void main(String[] args) {

        Program program = new Program();
        int value1 = program.reverse(32689358);
        int value2 = program.reverse(-32689358);

        int b = 0;

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread:"+Thread.currentThread().getName()+"---start");
            }
        }).start();

        System.out.println("main thread:"+Thread.currentThread().getName());
    }

    //整数反转
    public int reverse(int x) {
        int result = 0;
        while (x != 0) {
            int pop = x % 10;
            x = x / 10;
            //-2147483648——2147483647
            if (result > Integer.MAX_VALUE / 10 || (result == Integer.MAX_VALUE / 10 && pop > 7)) {
                return 0;
            }
            if (result < Integer.MIN_VALUE / 10 || (result == Integer.MIN_VALUE / 10 && pop < -8)) {
                return 0;
            }
            result = result * 10 + pop;
        }
        return result;
    }
}
